package com.aya.animal;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * @author liushang@zsyjr.com
 * @version 1.0
 * @description 描述信息
 * @date 2020/3/3
 **/
//@Adaptive
public class AdaptiveAnimal implements EarthAnimal {
    private List<EarthAnimal> animals;

    public AdaptiveAnimal() {
        List<EarthAnimal> animals = new ArrayList<>();
        ExtensionLoader<EarthAnimal> extensionLoader = ExtensionLoader.getExtensionLoader(EarthAnimal.class);
        Set<String> supportedExtensions = extensionLoader.getSupportedExtensions();
        for (String supportedExtension : supportedExtensions) {
            animals.add(extensionLoader.getExtension(supportedExtension));
        }
        this.animals = Collections.unmodifiableList(animals);
    }

    @Override
    public void saiHi(URL url) {
        String parameter = url.getParameter("adaptiveAnimalType", "lion");
        for (EarthAnimal animal : this.animals) {
            animal.saiHi(url);
        }
    }

    @Override
    public void sayReq(UserReq url) {

    }
}
